package com.itheima.Controller;

import com.github.pagehelper.Page;
import com.itheima.pojo.*;
import com.itheima.service.ClazzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/clazzs")
public class ClazzController {
    @Autowired
    private ClazzService clazzService;
//    查询全部
    @GetMapping("/list")
    public Result findAllto(){
        return Result.success(clazzService.findAllto());
    }

    //    删除操作
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") Integer id){
        clazzService.delete(id);
        return Result.success();
    }


    //新增班级
    @PostMapping
    public Result add(@RequestBody Clazz clazz){
        clazzService.add(clazz);
        return Result.success();
    }


    //条件分页查询
    @GetMapping
    public Result page(ClazzQueryParam clazzQueryParam){
        PageResult pageResult = clazzService.page(clazzQueryParam);
        return Result.success(pageResult);
    }








    //修改：
    //步骤一：回显
    @GetMapping("/{id}")
    public Result select(@PathVariable("id") Integer id){
        Clazz clazz= clazzService.select(id);
        return Result.success(clazz);
    }

    //步骤二：修改数据
    @PutMapping
    public Result update(@RequestBody Clazz clazz){
        return Result.success(clazzService.update(clazz));
    }
}
